package com.acme.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtil {
	public static final String YYMMDDHHMISS_FORMAT = "yyMMddhhmmss";
	public static final String DDMMYYYYHHMMSS_FORMAT = "dd/MM/yyyy hh:mm:ss";

	public String getDateInMilis(String date, String format)throws ParseException{
		String dateInMilis = null;
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		Date dateTmp = sdf.parse(date);
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(dateTmp);
		calendar.add(Calendar.HOUR, -6);
		dateInMilis = Long.toString(calendar.getTimeInMillis());
		return dateInMilis;
	}

	public String getDateFromMilis(String dateInMilis, String format) throws ParseException{
		String dateFormatted = null;
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
		Calendar calTemp = Calendar.getInstance();
		calTemp.setTimeInMillis(Long.parseLong(dateInMilis));
		dateFormatted = simpleDateFormat.format(calTemp.getTime());
		return dateFormatted;
	}
}